package com.kanshu.ksgb.fastread.doudou.module.personal.presenter;

import com.kanshu.ksgb.fastread.doudou.base.basemvp.BaseMvpPresenter;
import com.kanshu.ksgb.fastread.doudou.base.basemvp.IGenrialMvpView;
import com.kanshu.ksgb.fastread.doudou.common.net.INetCommCallback;
import com.kanshu.ksgb.fastread.doudou.common.net.bean.BaseResult;
import com.kanshu.ksgb.fastread.doudou.common.net.bean.PageRequestParams;
import com.kanshu.ksgb.fastread.doudou.module.login.bean.ChargeBean;
import com.kanshu.ksgb.fastread.doudou.module.login.bean.ConsumeBean;
import com.kanshu.ksgb.fastread.doudou.module.personal.bean.CommentBean;
import com.kanshu.ksgb.fastread.doudou.module.personal.bean.ThirdBindInfo;

import java.util.List;

import io.reactivex.subjects.Subject;

/**
 * Created by wcy on 2017\6\23 0023.
 */

public class AccountPresenter extends BaseMvpPresenter {
    PersonCenterModel mModel = new PersonCenterModel();
    IGenrialMvpView<BaseResult<List<ChargeBean>>> mChargeView;
    IGenrialMvpView<BaseResult<List<ConsumeBean>>> mConsumeView;
    IGenrialMvpView<BaseResult<List<CommentBean>>> mCommentView;
    IGenrialMvpView<BaseResult<ThirdBindInfo>> mThridView;

    public AccountPresenter(Subject lifeCyclerSubject) {
        super(lifeCyclerSubject);
    }

    public void setThirdBindView(IGenrialMvpView v) {
        mThridView = v;
    }
    public void setChargeView(IGenrialMvpView<BaseResult<List<ChargeBean>>> mvpView) {
        mChargeView = mvpView;
    }

    public void setConsumeView(IGenrialMvpView<BaseResult<List<ConsumeBean>>> mvpView) {
        mConsumeView = mvpView;
    }

    public void setCommentView(IGenrialMvpView<BaseResult<List<CommentBean>>> mvpView) {
        mCommentView = mvpView;
    }

    public void getChargeInfos(PageRequestParams params) {
        //mChargeView.showLoading(null);
        mModel.getChargeInfos(params, new INetCommCallback<BaseResult<List<ChargeBean>>>() {
            @Override
            public void onResponse(BaseResult<List<ChargeBean>> listBaseResult) {
                if (mChargeView == null) {
                    return;
                }
                mChargeView.dismissLoading();
                mChargeView.showContent(listBaseResult);
            }

            @Override
            public void onError(int code, String errDesc) {
                if (mChargeView == null) {
                    return;
                }
                mChargeView.dismissLoading();
                mChargeView.showError(code, errDesc);
            }
        });

    }

    public void getConsumeInfos(PageRequestParams params) {
        //mConsumeView.showLoading(null);
        mModel.getConsumeInfos(params, new INetCommCallback<BaseResult<List<ConsumeBean>>>() {
            @Override
            public void onResponse(BaseResult<List<ConsumeBean>> consumeBeen) {
                if (mConsumeView == null) {
                    return;
                }
                mConsumeView.dismissLoading();
                mConsumeView.showContent(consumeBeen);
            }

            @Override
            public void onError(int code, String errDesc) {
                if (mConsumeView == null) {
                    return;
                }
                mConsumeView.dismissLoading();
                mConsumeView.showError(code, errDesc);
            }
        });
    }


    @Override
    public void detachView() {
        mModel.cancel();
        mChargeView = null;
        mConsumeView = null;
        mCommentView = null;
        mThridView = null;
    }
}
